<div class="layui-fluid" id="drawing-add-mark">
    <form class="layui-form" action="" lay-filter="drawing-add-mark-form">
        <div class="layui-form-item">
            <div class="layui-form-item">
                <label class="layui-form-label febs-form-item-require">备注：</label>
                <div class="layui-input-block">
                    <select name="markIds" id="markIds"
                            lay-verify="required"
                            xm-select-direction="down"
                            xm-select="drawing-add-mark"
                            xm-select-skin="default">
                    </select>
                </div>
            </div>
            <div class="layui-form-item " style="float:right;">
                <button class="layui-btn" lay-submit="" lay-filter="drawing-add-mark-form-submit" id="submit">保存</button>
            </div>
            <div class="layui-form-item febs-hide">
                <input class="drawingId" name="drawingId"/>
            </div>
        </div>
    </form>
</div>

<script>

    layui.use(['febs', 'form', 'formSelects', 'validate'], function () {
        var $ = layui.$,
            febs = layui.febs,
            layer = layui.layer,
            formSelects = layui.formSelects,
            form = layui.form,
            drawingId = [[${drawingId}]],
            $view = $('#drawing-add-mark'),
            validate = layui.validate;

        form.verify(validate);
        form.render();

        formSelects.render();
        formSelects.config('drawing-add-mark', {
            searchUrl: ctx + 'markAll?id='+drawingId,
            response: {
                statusCode: 200
            },
            beforeSuccess: function (id, url, searchVal, result) {
                var data = result.data;
                var tranData = [];
                for (var i = 0; i < data.length; i++) {
                    tranData.push({
                        name: data[i].name
                        ,value: data[i].id
                        , selected: data[i].selected?'selected':''
                    })
                }
                result.data = tranData;
                $('.drawingId').val(drawingId);
                return result;
            },
            error: function (id, url, searchVal, err) {
                console.error(err);
                febs.alert.error('获取备注列表失败');
            }
        });
        form.on('submit(drawing-add-mark-form-submit)', function (data) {
            var markIds=  $view.find('input[name="markIds"]').val();
            /*console.log("drawingId"+drawingId);
            console.log("markIds"+markIds);*/
            febs.post(ctx + 'drawlingMark', {'drawingId':drawingId,'markIds':markIds}, function () {
                layer.closeAll();
                febs.alert.success('新增成功');
            });
            return false;
        });
    });

</script>